import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'normalize.css/normalize.css'
import './styles/index.scss'
import './styles/theme-variables.css'

import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'
import { i18n, setLocale } from './i18n'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { setupPermission } from './utils/permission'

// 创建应用实例
const app = createApp(App)

// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 使用插件
const pinia = createPinia()
app.use(pinia)
app.use(router)
app.use(ElementPlus, { size: 'medium' })
app.use(i18n)

// 从本地存储读取并设置语言
const savedLocale = localStorage.getItem('locale')
if (savedLocale) {
  setLocale(savedLocale)
}

// 设置权限指令
setupPermission(app)

// 挂载应用
app.mount('#app')